//
//  WJMainImageCell.m
//  WJBSApp
//
//  Created by rumble on 2018/11/23.
//  Copyright © 2018年 王景伟. All rights reserved.
//

#import "WJMainImageCell.h"

@interface WJMainImageCell ()
@property (nonatomic,strong) WJBaseImageView *belowImage;
@property (nonatomic,strong) UILabel *belowLable;
@end

@implementation WJMainImageCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    [self createImageCell];
    return self;
}

- (void)createImageCell {
    
    self.belowImage = [[WJBaseImageView alloc]init];
    self.belowImage.hidden = YES;
    self.belowImage.backgroundColor = BSClearColor;
    self.belowImage.image = [UIImage imageNamed:@"see-big-picture-background"];
    [self.detailImage addSubview:self.belowImage];
    self.belowImage.userInteractionEnabled = YES;
    UITapGestureRecognizer *belowImageTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickBelowImage)];
    [self.belowImage addGestureRecognizer:belowImageTap];
    
    self.belowLable = [[UILabel alloc]init];
    self.belowLable.hidden = YES;
    self.belowLable.text = @"点击查看全图";
    self.belowLable.backgroundColor = BSClearColor;
    self.belowLable.textColor = BSWhiteColor;
    self.belowLable.textAlignment = 1;
    [self.belowImage addSubview:self.belowLable];
}

- (void)setLayout:(WJMianLayout *)layout {
    [super setLayout:layout];
        
    if (layout.isScale) {
        [self hiddenBelow:NO];
        self.belowImage.frame = CGRectMake(0, layout.imageRect.size.height - 40, kBSContentW, 40);
        self.belowLable.frame = CGRectMake(0, 0, kBSContentW, 40);
    } else {
        [self hiddenBelow:YES];
    }
    
    switch (layout.style) {
        case WJMianLayoutImage:
            self.belowLable.text = @"点击查看全图";
            break;
        case WJMianLayoutHtml:
            self.belowLable.text = @"点击查看全文";
            break;
        default:
            break;
    }
}

- (void)hiddenBelow:(BOOL)isHidden {
    self.belowImage.hidden = isHidden;
    self.belowLable.hidden = isHidden;
}

- (void)clickBelowImage {
    if (self.cellDelegate && [self.cellDelegate respondsToSelector:@selector(mainTableViewCellClickImageWithLayout:imageView:isPush:)]) {
        [self.cellDelegate mainTableViewCellClickImageWithLayout:self.layout imageView:self.detailImage isPush:NO];
    }
}
@end
